package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.SelfTeamDeviceEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import java.util.List;

/**
 * Time:2021/3/15
 * AUTHOR:F_Q
 * Description:选择工队设备条目处理
 */
public class WorkEquipmentAdapter extends BaseRecycleAdapter<SelfTeamDeviceEntity> {

    public WorkEquipmentAdapter(Context context, List<SelfTeamDeviceEntity> datas) {
        super(context, R.layout.item_work_equipment, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final SelfTeamDeviceEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ImageView imgLogo = holder.itemView.findViewById(R.id.img_logo);
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.mechanical)
                .transforms(new CenterCrop(), new RoundedCorners(8));
        if (!TextUtils.isEmpty(entity.getPicture())){
            String[] split = entity.getPicture().split(",");
            Glide.with(context).load(split[0]).apply(options).into(imgLogo);
        }else {
            Glide.with(context).load(R.mipmap.mechanical).apply(options).into(imgLogo);
        }
        CheckBox checkBox = holder.itemView.findViewById(R.id.checkbox);
        checkBox.setChecked(entity.isIslooks());
        LinearLayout details = holder.itemView.findViewById(R.id.details);
        checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean islooks = entity.isIslooks();
                entity.setIslooks(!islooks);
                checkedbos.selectData();
                notifyDataSetChanged();
            }
        });
        details.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkedbos.detailsData(entity.getId(),entity.getNo());
            }
        });
    }
    private OnCheckedChangeCheckBox checkedbos;

    public void setCheckedbos(OnCheckedChangeCheckBox checkedbos) {
        this.checkedbos = checkedbos;
    }

    public interface OnCheckedChangeCheckBox {

        void selectData();

        void detailsData(String id,String no);
    }
}
